package Main;

import Audio.MP3;
import Control.GameController;
import Engine.KeyManager;
import Engine.MenuActions;
import com.sun.opengl.util.FPSAnimator;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.media.opengl.GLCanvas;



/**
 * SpiritOfTheSpaceInvaders.java
 * @author Gustavo Buzogany Eboli
 * @version 1.0
 */
public class SpiritOfTheSpaceInvaders
{
    /**
     * Fun??o principal da aplica??o.
     * @param args argumentos do programa.
     */
    public static void main(String[] args) {
        Frame frame = new Frame("Spirit of The Space Invaders");
        GLCanvas canvas = new GLCanvas();
        GameController gc = GameController.getInstance();
        MenuActions ma = MenuActions.getInstance();

        canvas.addGLEventListener(gc);

        KeyManager km = new KeyManager(ma);
        km.setActionHandlerMaster(km);

        canvas.addKeyListener(km);

        frame.add(canvas);

        File musicaArq = new File("nice.mp3");
        MP3 musica = new MP3(musicaArq);
        new Thread(musica).start();

        frame.setSize(1024, 768);
        final FPSAnimator animator = new FPSAnimator(canvas, 60);
        frame.addWindowListener(new WindowAdapter()
        {
            @Override
            public void windowClosing(WindowEvent e) {
                new Thread(new Runnable() {

                    public void run() {
                        animator.stop();
                        System.exit(0);
                    }
                }).start();
            }
        });
        // Center frame
        //frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        animator.start();
    }
}